<?php
/*
 * CSession类
 * @author andery <andery@foxmail.com>
 * @link http://www.Nimo.com/
 * @version $Id: CSession.lib.php 2010-07-23 19:27:10Z andery $
 */
class CSession{
    protected $sess_name;
    protected $sess_id;
    protected $sess_type;
    private   $_sess_obj;

    public function __construct($sess_type='')
    {
        CLang::load('lib.Session');
        empty($sess_type) ? $this->sess_type = CConf::get('session.session_type') : $this->sess_type = $sess_type;
        require_once( dirname(__FILE__) . '/session/ISession.php');
        $sess_class = 'C' . trim($this->sess_type) . 'Session';
        require_once( dirname(__FILE__) . '/session/' . $sess_class . '.php');
        $this->sess_name = CConf::get('session.session_name');
        if (class_exists($sess_class)) {
            $this->_sess_obj = new $sess_class($this->sess_name);
        } else {
            throw new CException(CLang::get('session_type_invalid'));
        }
        $this->init_handler();
        session_start();
    }
    
    private function init_handler()
    {
        session_set_save_handler(
	        array ($this->_sess_obj, "sess_open"),
            array ($this->_sess_obj, "sess_close"),
            array ($this->_sess_obj, "sess_read"),
            array ($this->_sess_obj, "sess_write"),
            array ($this->_sess_obj, "sess_destroy"),
            array ($this->_sess_obj, "sess_gc")
        );
    }
}